package cn.lingyangwl.agile.auth.assembly;

import cn.lingyangwl.agile.auth.model.entity.OAuth2Client;
import cn.lingyangwl.agile.auth.model.rqrs.client.OAuthClientResp;
import cn.lingyangwl.agile.auth.model.rqrs.client.OAuthClientSaveReq;
import cn.lingyangwl.agile.auth.model.rqrs.client.OAuthClientUpdateReq;
import cn.lingyangwl.agile.model.BaseAssembly;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.Mappings;

/**
 * oauth客户端
 *
 * @author shenguangyang
 */
@Mapper(componentModel = "spring")
public interface AuthClientDetailsAssembly extends BaseAssembly {
  @Mappings({
          @Mapping(source = "authorizedGrantTypes", target = "authorizedGrantTypes", qualifiedByName = LIST_TO_STR),
          @Mapping(source = "scope", target = "scope", qualifiedByName = LIST_TO_STR),
  })
  OAuthClientResp toAuthClientDetailsResp(OAuth2Client source);

  @Mappings({
          @Mapping(source = "authorizedGrantTypes", target = "authorizedGrantTypes", qualifiedByName = STR_TO_LIST),
          @Mapping(source = "scope", target = "scope", qualifiedByName = STR_TO_LIST),
  })
  OAuth2Client toAuthClientDetails(OAuthClientSaveReq source);

  @Mappings({
          @Mapping(source = "authorizedGrantTypes", target = "authorizedGrantTypes", qualifiedByName = STR_TO_LIST),
          @Mapping(source = "scope", target = "scope", qualifiedByName = STR_TO_LIST),
  })
  OAuth2Client toAuthClientDetails(OAuthClientUpdateReq source);
}
